<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/resources/template/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:p="http://primefaces.org/ui"                    
                xmlns:bi="http://java.sun.com/jsf/composite/bill"
                xmlns:pa="http://java.sun.com/jsf/composite/paymentMethod">
    <ui:define name="content">
        <h:panelGroup >
            <h:form  >
                <p:panel rendered="#{!pharmacyDealorBill.printPreview}" >
                    <f:facet name="header" >
                        <h:panelGrid columns="15"  >
                            <h:outputLabel value="Cash Bill" />
                            <h:outputLabel value="&nbsp;&nbsp;&nbsp;&nbsp;" style="min-width: 50px;" />
                            <p:selectOneMenu   id="cmbPs" value="#{pharmacyDealorBill.current.paymentMethod}">                                                                     
                                <f:selectItems value="#{enumController.paymentMethodsWithoutCredit}"  />
                                <p:ajax process="cmbPs"
                                        update="creditCard cheque slip " event="change" />

                            </p:selectOneMenu>
                            <h:panelGroup id="creditCard" style="display: #{pharmacyDealorBill.current.paymentMethod ne 'Card' ? 'none' : 'block'} ; ">
                                <pa:creditCard paymentMethodData="#{pharmacyDealorBill.paymentMethodData}"/>
                            </h:panelGroup>

                            <h:panelGroup id="cheque" style="display: #{pharmacyDealorBill.current.paymentMethod ne 'Cheque' ? 'none' : 'block'} ; " >
                                <pa:cheque paymentMethodData="#{pharmacyDealorBill.paymentMethodData}"/>
                            </h:panelGroup>

                            <h:panelGroup id="slip" style="display: #{pharmacyDealorBill.current.paymentMethod ne 'Slip' ? 'none' : 'block'} ;">
                                <pa:slip paymentMethodData="#{pharmacyDealorBill.paymentMethodData}"/>
                            </h:panelGroup>

                            <p:commandButton id="btnSettle" value="Settle" action="#{pharmacyDealorBill.settleBillAll}" ajax="false"  style="width: 150px; padding: 1px;border: 1px solid ; margin: auto;">
                            </p:commandButton>
                            <p:defaultCommand target="btnSettle"/>

                            <p:commandButton value="New Bill" ajax="false" action="#{pharmacyDealorBill.makeNull()}" >
                            </p:commandButton>#{pharmacyDealorBill.current.createdAt}

                        </h:panelGrid>
                    </f:facet>
                    <h:panelGrid columns="2" style="min-width: 100%;">
                        <h:panelGrid columns="1">
                            <h:outputLabel value="Type GRN No or Dealor Name"/>                           
                            <p:autoComplete widgetVar="aIx" id="acIx" forceSelection="true" 
                                            value="#{pharmacyDealorBill.institution}"
                                            completeMethod="#{institutionController.completeSuppliers}"
                                            var="ix" itemLabel="#{ix.name}"
                                            itemValue="#{ix}" size="30"  style="width: 400px;"
                                            converter="institutionConverter">                                  
                                <p:column headerText="Name">
                                    #{ix.name}
                                </p:column>
                                <p:column headerText="Code">
                                    #{ix.institutionCode}
                                </p:column>
                                <f:ajax event="itemSelect" execute="@this" 
                                        render=" :#{p:component('itms')} total" 
                                        listener="#{pharmacyDealorBill.selectInstitutionListener()}"/>
                            </p:autoComplete>  
                            <p:panel  id="total" style="min-width: 100%;">

                                <p:panelGrid  columns="2" >
                                    <p:outputLabel value="Net Total" />
                                    <p:outputLabel  value="#{pharmacyDealorBill.current.netTotal}">
                                        <f:convertNumber pattern="#,##0.00" />
                                    </p:outputLabel>

                                    <p:outputLabel value="Description"/>
                                    <p:inputTextarea value="#{pharmacyDealorBill.current.comments}"/>                                                         
                                </p:panelGrid>
                            </p:panel>

                        </h:panelGrid>

                        <p:dataTable  value="#{pharmacyDealorBill.billItems}"
                                      selection="#{pharmacyDealorBill.selectedBillItems}" 
                                      var="b" id="itms" rowKey="#{b.searialNo}" 
                                      selectionMode="multiple"
                                      scrollable="true"
                                      scrollHeight="300">
                            <f:facet name="header">
                                <h:outputLabel value="Paying Institution : "/>
                                <h:outputLabel value="#{pharmacyDealorBill.current.toInstitution.name}"/>
                                <p:commandButton ajax="false" action="#{pharmacyDealorBill.removeAll()}" value="Remove Selected"/>
                            </f:facet>

                            <p:ajax event="rowSelect"  process="@this" 
                                    update=":#{p:component('total')}"
                                    listener="#{pharmacyDealorBill.calTotalBySelectedBillTems()}" />  


                            <p:column >  
                                <f:facet name="header">
                                    <h:outputLabel value="GRN No"/>                                  
                                </f:facet>                              
                                #{b.referenceBill.deptId}
                            </p:column> 
                            <p:column headerText="GRN Amount">
                                <p:outputLabel value="#{b.referenceBill.netTotal}">
                                    <f:convertNumber pattern="#,##0.00" />
                                </p:outputLabel>
                            </p:column>
                            <p:column headerText="GRN Return Amount">
                                <p:outputLabel value="#{b.referenceBill.tmpReturnTotal}">
                                    <f:convertNumber pattern="#,##0.00" />
                                </p:outputLabel>
                            </p:column>
                            <p:column headerText="Paid Amount">
                                <p:outputLabel value="#{b.referenceBill.paidAmount}">
                                    <f:convertNumber pattern="#,##0.00" />
                                </p:outputLabel>
                            </p:column>
                            <p:column headerText="Recievable Amount">
                                <p:outputLabel value="#{(b.referenceBill.netTotal+
                                                        b.referenceBill.tmpReturnTotal+
                                                        b.referenceBill.paidAmount)}">
                                    <f:convertNumber pattern="#,##0.00" />
                                </p:outputLabel>
                            </p:column>
                            <p:column headerText="Paying Amount">
                                <p:inputText autocomplete="off" value="#{b.netValue}">    
                                    <f:convertNumber pattern="#,##0.00" />
                                    <f:ajax event="blur" execute="@this" render="@all" listener="#{pharmacyDealorBill.changeNetValueListener(b)}"/>
                                </p:inputText>
                            </p:column>

                            <p:column headerText="Remove">
                                <p:commandButton ajax="false" action="#{pharmacyDealorBill.remove(b)}" value="X">
                                </p:commandButton>
                            </p:column>
                        </p:dataTable>

                    </h:panelGrid>

                </p:panel>
               
                <p:panel rendered="#{pharmacyDealorBill.printPreview}">                                
            <p:commandButton value="Print" ajax="false" action="#" >
                <p:printer target="gpBillPreview" ></p:printer>
            </p:commandButton>
            <p:commandButton value="New Bill" ajax="false" action="#{pharmacyDealorBill.makeNull()}" >
                    </p:commandButton>
            <p:panel   id="gpBillPreview"   >

                <bi:grn_payment billItems="#{pharmacyDealorBill.selectedBillItems}" bill="#{pharmacyDealorBill.current}"/>
                
               

            </p:panel>
        </p:panel>
            </h:form>
        </h:panelGroup>
        
        
        
    </ui:define>

</ui:composition>
